<%-- 
    Document   : horasValidas
    Created on : 25-jun-2013, 5:00:15
    Author     : juli
--%>

<%@page import="beans.Validator"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="model.Meeting"%>
<%@page import="java.util.List"%>
<%@page import="beans.Dao"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="CSS/style.css"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Select a Meeting Hour:</h1>
        <p style="color: #ff0000">${sessionScope['error']}</p>
        <form action="SendInvitation" method="post">
            
           <%
               
           HttpSession respuesta = request.getSession(true);
           Integer id_inv=Integer.parseInt(respuesta.getAttribute("sessionInv").toString());
           Validator v=new Validator();
           //Todas las citas para un dia en esa sala ordenadas por hora init
           List<Meeting> meetings = Dao.getMeetingsByRoomAndDay(id_inv);
           Dao d = new Dao();
           d.conectar();
           d.desconectar();
           for(Meeting m:meetings){
            out.print(m.getDay());
           }
           List<String> horas=new ArrayList<String>();
           //Meto todas las horas en la lista de horas
           horas.add("00:00");
           for(Meeting m: meetings ){
               horas.add(m.getHourInit());
               horas.add(m.getHourFinal());
           }horas.add("24:00");
           
           out.print(horas.toString());
           //Segun todos los meetings, saco las combinaciones de hora init y fin
             for(int contador=0; contador < horas.size(); contador++){
                     int c=0;
                 if(contador%2==0){
                     c++;
                 //Hora init y final de cada reunion
                 String init=horas.get(contador);
                 String fin=horas.get(contador+1);
                     //OPTION 1
                        out.println("<p> Option "+c+" ");  
                        out.println("<p> Select Hour Initial: ");
                        //Seleccionar la HOUR INICIAL
                        out.println("<select name='hourI'>");
                        out.println("<option selected>--- Select a Hour Initial ---</option>");
                        //HOUR
                        for (int i=0;i<24;i++){
                            //MINUTE
                            for (int j=0; j<60; j++){
                                 String x=Integer.toString(i)+":"+Integer.toString(j);
                                 if(v.isHourBiggerThan(x,init) && v.isHourBiggerThan(fin,x)){
                                    out.println("<option>"+x+"</option>");
                                }}
                            }
                        
                        out.println("</option></p></select>");
                        //Seleccionar la HOUR FINAL
                        out.println("<p> Select Hour Final ");
                        out.println("<select name='hourF'>");
                        out.println("<option selected>--- Select a Hour Final ---</option>");
                        //HOUR
                        for (int i=0;i<24;i++){
                            //MINUTE
                            for (int j=0; j<60; j++){
                                String x=Integer.toString(i)+":"+Integer.toString(j);
                                 if(v.isHourBiggerThan(x,init) && v.isHourBiggerThan(fin,x)){
                                 out.println("<option>"+x+"</option>");
                                }
                            }}
                        out.println("</option></select></p></p>"); 
                 }
           }
             %>    
          <p><input type="submit" value="Ok"></p>
        </form>
                  </div>
            </section>
        </div>
    </body>
</html>